

function verifyRec(index){
	if(verifyFullName(index) && verify_m_p_e(index) && verifyMobile(index) && verifyPhone(index) && verifyQh(index) && verifyExtNumber(index) &&
			verifyProvinceName(index) && verifyCityName(index) && //verifyCountyName(index) &&
			verifyAddress(index) &&  verifyGoods(index) && verifyQuantity(index) &&
			verifyAccount(index) && verifyPrice(index)){
		return true;
	}
	return false;
}

function verifyFullName(index){
	var form = $("#recForm" + index);
	var fullname = form.find("input[@type=text][name=rfullname]");
	var fullname_valid = form.find("span[id=rec_Validform_checktip]");
	if (fullname.val() == '' || fullname.val() == undefined) {
		//fullname.focus();
		fullname_valid.text(i18n.order_enter_recipient_name).addClass(
				"Validform_wrong");
		return false;
	} else {
		fullname_valid.text("").removeClass("Validform_wrong");
	}
	return true;
}
function verify_m_p_e(index){
	var form = $("#recForm"+index);
	var mobile =form.find("input[@type=text][name=rmobile]");
	var phone = form.find("input[@type=text][name=rphone]");
	var extNumber = form.find("input[@type=text][name=rextnumber]");
	var phone_valid = form.find("span[id=rec_Validform_checktip]");
	if(mobile.val() =='' && phone.val()=='' && extNumber.val()==''){
		//mobile.focus();
		phone_valid.text(i18n.order_phone_or_telephone).addClass("Validform_wrong");
		return false;
	}else if(mobile.val() !='' || phone.val()!=''){
		phone_valid.text("").removeClass("Validform_wrong");
	}
	return true;
}
function verifyMobile(index){
	var form = $("#recForm" + index);
	var mobile = form.find("input[@type=text][name=rmobile]");
	var mobile_valid = form.find("span[id=rec_Validform_checktip]");
	var phone_valid = form.find("span[id=rec_Validform_checktip]");
	if(mobile.val()!=''){
		var reg =/^13[0-9]{9}$|14[0-9]{9}|15[0-9]{9}$|17[0-9]{9}$|18[0-9]{9}$/;
		if(!reg.test(mobile.val())){
			//mobile.focus();
			phone_valid.text("").removeClass("Validform_wrong");
			mobile_valid.text(i18n.order_phone_invalid).addClass("Validform_wrong");
			return false;
		}else{
			mobile_valid.text("").removeClass("Validform_wrong");
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}else{
		mobile_valid.text("").removeClass("Validform_wrong");
	}
	return true;
}

function verifyPhone(index){
	var form = $("#recForm" + index);
	var phone = form.find("input[@type=text][name=rphone]");
	var rqh = form.find("input[@type=text][name=rqh]");
	var phone_valid = form.find("span[id=rec_Validform_checktip]");
	if(phone.val() !=''){
		var reg = /^\d{6,12}$/;
		if(!reg.test(phone.val())){
			//phone.focus();
			phone_valid.text(i18n.user_telphone_invalid).addClass("Validform_wrong");
			return false;
		}else{
			var rqh_reg=/^\d{3,4}$/;
			if(rqh.val() != ''){
				if(!rqh_reg.test(rqh.val())){
					phone_valid.text(i18n.order_areacode_style_wrong).addClass("Validform_wrong");
					return false;
				}
			}
			var rextnumber_reg=/^\d{1,5}$/;
			var rextnumber = form.find("input[@type=text][name=rextnumber]");
			if(rextnumber.val() != ''){
				if(!rextnumber_reg.test(rextnumber.val())){
					phone_valid.text(i18n.order_Ext_style_wrong).addClass("Validform_wrong");
					return false;
				}
			}
			
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}else{
		if(verifyMobile(index)){
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}
	return true;
}
function verifyExtNumber(index){
	
	var form = $("#recForm" + index);
	var rextnumber = form.find("input[@type=text][name=rextnumber]");
	var phone = form.find("input[@type=text][name=rphone]");
	var phone_valid = form.find("span[id=rec_Validform_checktip]");
	if(rextnumber.val() != ''){
		var reg = /^\d+$/;
		var reg2 = /^\d{6,8}$/;
		if(!reg.test(rextnumber.val())){
			//rextnumber.focus();
			phone_valid.text(i18n.order_Ext_style_wrong).addClass("Validform_wrong");
			return false;
		}else if(!reg2.test(phone.val())){
			//phone.focus();
			phone_valid.text(i18n.user_telphone_invalid).addClass("Validform_wrong");
			return false;
		}else{
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}else{
		if(verifyMobile(index) && verifyPhone(index)){
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}
	return true;
}

function verifyQh(index){
	
	var form = $("#recForm" + index);
	var rqh = form.find("input[@type=text][name=rqh]");
	var phone = form.find("input[@type=text][name=rphone]");
	var phone_valid = form.find("span[id=rec_Validform_checktip]");
	if(rqh.val() != ''){
		var reg = /^\d+$/;
		var reg2 = /^\d{6,8}$/;
		if(!reg.test(rqh.val())){
			//rextnumber.focus();
			phone_valid.text(i18n.order_areacode_style_wrong).addClass("Validform_wrong");
			return false;
		}else if(!reg2.test(phone.val())){
			//phone.focus();
			phone_valid.text(i18n.user_telphone_invalid).addClass("Validform_wrong");
			return false;
		}else{
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}else{
		if(verifyMobile(index) && verifyPhone(index)){
			phone_valid.text("").removeClass("Validform_wrong");
		}
	}
	return true;
}

function verifyProvinceName(index){
	var form = $("#recForm" + index);
	var provinceName = form.find("input[@type=text][name=rprovinceName]");
	var provinceId = form.find("input[@type=text][name=rprovinceId"+index+"]");
	var prodType = form.find("select#prodType");
	if (provinceName.val() == ''
			|| provinceName.val() == provinceName.attr("tip")) {
		//provinceName.focus();
		$("#rec_Validform_checktip").text(i18n.order_province_invalid).addClass("Validform_wrong");
		return false;
	} else {
		$("#rec_Validform_checktip").text("").removeClass("Validform_wrong");
	}
	if (provinceId.val() == ''
			|| provinceId.val() == provinceId.attr("tip")) {
		//provinceName.focus();
		$("#rec_Validform_checktip").text(i18n.order_province_invalid).addClass("Validform_wrong");
		return false;
	} else {
		$("#rec_Validform_checktip").text("").removeClass("Validform_wrong");
	}
	if(inArray(provinceId.val(), noneCrabsProList)&&prodType.val()=="SP334"){
		$("#rec_Validform_checktip").text(i18n.none_crabs_pri_province).addClass("Validform_wrong");
		return false;
	}else{
		$("#rec_Validform_checktip").text("").removeClass("Validform_wrong");
	}
	return true;
}

function verifyCityName(index){
	var form = $("#recForm" + index);
	var cityName = form.find("input[@type=text][name=rcityName]");
	if (cityName.val() == '' || cityName.val() == cityName.attr("tip")) {
		//cityName.focus();
		$("#rec_Validform_checktip").text(i18n.order_city_invalid).addClass("Validform_wrong");
		return false;
	} else {
		$("#rec_Validform_checktip").text("").removeClass("Validform_wrong");
	}
	var cityId = form.find("input[@type=text][name=rcityId"+index+"]");
	if (cityId.val() == '' || cityId.val() == cityId.attr("tip")) {
		//cityName.focus();
		$("#rec_Validform_checktip").text(i18n.order_city_invalid).addClass("Validform_wrong");
		return false;
	} else {
		$("#rec_Validform_checktip").text("").removeClass("Validform_wrong");
	}
	return true;
}

/*function verifyCountyName(index){
	var form = $("#recForm" + index);
	var countyName = form.find("input[@type=text][name=rcountyName]");
	if (countyName.val() == '' || countyName.val() == countyName.attr("tip")) {
		countyName.focus();
		return false;
	}
	var countyId = form.find("input[@type=text][name=rcountyId"+index+"]");
	if (countyId.val() == '' || countyId.val() == countyId.attr("tip")) {
		countyName.focus();
		return false;
	}
	return true;
}*/

function verifyAddress(index){
	var form = $("#recForm" + index);
	var address = form.find("input[@type=text][name=raddress]");
	if (address.val() == '' || address.val() == address.attr("tip")) {
		//address.focus();
		$("#rec_Validform_checktip").text(i18n.order_address_empty).addClass("Validform_wrong");
		return false;
	} else {
		$("#rec_Validform_checktip").text("").removeClass("Validform_wrong");
	}

	return true;
}

function verifyQuantity(index){
	var form = $("#recForm" + index);
	var quantity = form.find("input[@type=text][name=quantity]");
	var quantity_valid = form.find("span[id=rec_Validform_checktip]");
	if (quantity.val() == '') {
		//quantity.focus();
		quantity_valid.text(i18n.order_shipments_amount_empty).addClass(
				"Validform_wrong");
		return false;
	} else if (quantity.val() == '0') {
		quantity_valid.text(i18n.order_shipments_amount_zero).addClass(
				"Validform_wrong");
		return false;
	} else if (quantity.val() != '') {
		var regx = /^[1-9]\d{0,5}?$/;
		if (!regx.test(quantity.val())) {
			quantity_valid.text(i18n.order_shipments_amount_wrong).addClass(
					"Validform_wrong");
			return false;
		} else {
			quantity_valid.text("").removeClass("Validform_wrong");
		}
	}
	return true;
}

function verifyGoods(index){
	var form = $("#recForm" + index);
	var goods = form.find("input[@type=text][name=goods]");
	var goods_valid = form.find("span[id=rec_Validform_checktip]");
	if (goods.val() == '') {
		//goods.focus();
		goods_valid.text(i18n.order_add_shipments)
				.addClass("Validform_wrong");
		return false;
	} else {
		goods_valid.text("").removeClass("Validform_wrong");
	}
	return true;
}

function verifyPrice(index){
	var form = $("#recForm" + index);
	var msgBox = form.find("span[id=rec_Validform_checktip]");
	return validateInsure(msgBox);
}

function verifyAccount(index){
	var isMedicineOrderTrustRecept = false;
	if(location.pathname.indexOf('order_medicine.html')>-1){
		if($('#trustRecept:checked').length>0)isMedicineOrderTrustRecept = true;
	}
	var form = $("#recForm" + index);
	var account = form.find("input[@type=text][name=account]");
	var payway = form.find("select[name=payway]");
	if(("1" == payway.val() || "2" == payway.val())&&!isMedicineOrderTrustRecept){//寄付现结，到付,医药件非代收货款 不需验证月结账号
		return true;
	}
	var val=account.val();
	var account_valid = form.find("span[id=rec_Validform_checktip]");
	if($.trim(val)!=val){
		account_valid.text(i18n.contain_blank).addClass("Validform_wrong");
		//account.focus();
		return false;
	}
	if(val=="" || val==undefined){
		account_valid.text(i18n.order_account_empty).addClass("Validform_wrong");
		//account.focus();
		return false;
	}
	for(var i=0;i<val.length;i++){
		if(val.charAt(i)>='0' && val.charAt(i)<='9'){
			
		}else{
			account_valid.text(i18n.cardno_only_num).addClass("Validform_wrong");
			//account.focus();
			return false;
		}
	}
	if(val.length!=10){//月结账号目前规定为10位
		account_valid.text(i18n.cardno_ten_digits).addClass("Validform_wrong");
		//account.focus();
		return false;
	}
	var result=true;
	//判断是否是有效的月结卡号。返回网点代码不为空的则是有效卡号
	if(isMedicineOrderTrustRecept){
		syncCallService('/service/order/batch/deptcode?cardNo='+val+"&time="+new Date().getTime(), 'get', 'json', '',
			function(data){
			if(data==null || data==''){
				account_valid.text(i18n.cardno_invalid).addClass("Validform_wrong");
				//account.focus();
				result= false;
			}
		},function(){
		});
	}
	 
	if(result==false){
		return false;
	}
	account_valid.text("").removeClass("Validform_wrong");
	return true;
	
}

function verifyPackNum(){
	var form = $("#recForm");
	var packNum_valid = form.find("span[id=rec_Validform_checktip]");
	var packNum = form.find("input[@type=text][name=packNum]");
	var reg = /^\d+$/;
	if(packNum.val() == ''){
		packNum_valid.text(i18n.order_packnum_emtry).addClass("Validform_wrong");
		return false;
	}else if(!reg.test(packNum.val()) || packNum.val() < 1){
		packNum_valid.text(i18n.order_packnum_error).addClass("Validform_wrong");
		return false;
	}
	return true;
	
}
